<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03_JS数据类型</title>
</head>
<body>
<script>
    //数据类型 = 原始类型 + 引用类型
    // 原始类型:number,string,boolean,null,undefined
    var a = 1;
    var b = 3.14;
    console.log(a,typeof a,b,typeof b);
    var c = 'hello';
    var d = "world";
    console.log(c,typeof c,d,typeof d);
    var e = true;
    var f = false;
    console.log(e,typeof e,f,typeof f);
    var g ;//声明了变量，但未赋值,推断不出来类型,就是未定义型
    console.log(g, typeof g);//undefined未定义型

    //引用类型 Object Array Function Date...
    let obj = {};
    console.log(obj,typeof obj);
    obj.name = '张三';
    obj.age = 18;
    console.log(obj);
    console.log(obj.name,obj.age);

    let obj2 = {
        name:'张三',
        age:18
    };
    console.log(obj2);
    obj2.like = "吃火锅";
    console.log(obj2);
    console.log(obj2.name,obj2.age);
    console.log(obj2.play);//访问对象不存在的属性,会得到undefined

    //数组
    let arr = [1,3.14,'aaa',true];
    console.log(arr,typeof arr);//[1, 3.14, 'aaa', true] 'object'
    console.log(arr[0],arr[1],arr[2],arr[3]);
    console.log(arr[99]);//访问数组不存在的下标,会得到undefined

    //Number(): 将数据转换为数字类型的结果,如果得不到数字类型的结果就会得到NaN
    console.log(Number(true),typeof Number(true));//1 'number'
    console.log(Number(false));//0 'number'
    console.log(Number('123'));//123 'number'
    console.log(Number(23.5));//23.5 'number'
    console.log(Number("hhh"));//NaN (Not a Number)

    //Boolean():将数据转换为布尔类型的结果
    console.log(Boolean(0));
    console.log(Boolean(null));
    console.log(Boolean(undefined));
    console.log(Boolean(NaN));
    console.log(Boolean(''));
    console.log('0 null undefiend NaN 空串 以上5个值转为布尔类型的结果都为false!');
    console.log(Boolean(' '));
    console.log(Boolean('hhh'));
    console.log(Boolean(1));

</script>
</body>
</html>